package com.learn.demo.controller;

import com.learn.demo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * @author banjiawei
 * @date 2020/08/24
 * 模拟第三方接口
 */
@RestController
@RequestMapping("/third/party")
@Slf4j
public class ThirdPartyController {

    @PostMapping("/login")
    public String login(String userName, String pwd){
        Assert.notNull(userName, "用户名不能为空");
        Assert.notNull(pwd, "密码不能为空");
        log.info("登录成功");
        return "登录成功";
    }

    @PostMapping("/login/user")
    public String login(@RequestBody User user){
        Assert.notNull(user, "参数错误");
        Assert.notNull(user.getUserName(), "用户名不能为空");
        Assert.notNull(user.getPwd(), "密码不能为空");
        log.info("登录成功");
        return "登录成功";
    }

    @GetMapping("/login/timeout")
    public void loginTimeout(){
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("沉睡三秒");
    }
}
